Ext.namespace('Ext.ux.calendar');

Ext.ux.calendar.CalendarGrid = Ext.extend(Ext.ux.grid.GroupGrid, {
	
	initComponent: function(){
		
		var gridStructure = [{
			name: 'eventId',
			hidden: true
		},{
			name: 'calendarId',
			header: '事件类型',
			width: 120,
			sortable: true
		},{
			name: 'title',
			header: '标题',
			width: 120,
			sortable: true
		},{
			name: 'startTime',
			header: '开始时间',
			width: 120,
			sortable: true
		},{
			name: 'endTime',
			header: '结束时间',
			width: 120,
			sortable: true
		},{
			name: 'isAllDay',
			header: '是否整天',
			width: 40,
			type: 'boolean',
			sortable: false
		},{
			name: 'url',
			header: '网址',
			sortable: true
		},{
			name: 'location',
			header: '地点',
			sortable: true
		},{
            header: '便签',
			name: 'notices',
			sortable: true
		},{
			name: 'reminder',
			header: '提醒',
			sortable: true
		}];
		
		
		this.structure = gridStructure;
		
		this.defaultSortField = 'startTime';
		this.keyField = 'eventId';
		
		
	    this.tbar = new Ext.Toolbar();
	    this.tbar.addItem({
	    	text: '更多日程...'
	    });
	    this.tbar.addItem('->');
	    this.tbar.addItem({
			text: '分组显示',
			enableToggle: true,
			pressed: this.groupField != null ? true : false,
			iconCls: 'icon-collapse-all',
			toggleHandler: function(item, pressed){
				if(pressed){
					var field = this.groupByCombo.getValue() == '' ? this.groupField : this.groupByCombo.getValue();
					this.store.groupBy(field, true);
					this.groupByCombo.enable();
				}else{
					this.store.clearGrouping();
					this.groupByCombo.disable();
				}
			},
			scope: this
		});
		this.tbar.addItem(' ');
		
		var groupByComboStore = new Ext.data.ArrayStore({
	        fields: ['name', 'header'],
	        data: [['title', '标题'],
	        		['isAllDay', '是否整天']
	        	]
	    });
	    
		var groupByCombo = new Ext.form.ComboBox({
	        store: groupByComboStore,
	        displayField: 'header',
	    	valueField: 'name',
	    	editable: false,
	    	allowBlank: true,
	        mode: 'local',
	        triggerAction: 'all',
	        emptyText: '选择分组字段...',
	        selectOnFocus: true,
	        width: 110
	    });
		groupByCombo.on('select', function(combo, record, index){
			var gorupByColumn = record.get('name');
			this.store.groupBy(gorupByColumn, true);
		}, this);
		
		
		this.tbar.addItem(groupByCombo);
		this.groupByCombo = groupByCombo;
		
		this.tbar.addItem('-');
		
		
		Ext.ux.calendar.CalendarGrid.superclass.initComponent.call(this);
		
		
		
	}
});